<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="../common/header.jsp" %>

<!-- 修改密码窗口 -->
<div id="edit-dialog" class="easyui-layout"
    style="width:450px; padding:10px;">
    <form id="edit-form" method="post">
        <table>
            <tr>
                <td width="80" align="right">用户名:</td>
                <td><input type="text" name="username" class="wu-text easyui-validatebox" readonly="readonly"
                           value="${admin.username}"/></td>
            </tr>
            <tr>
                <td width="80" align="right">原密码:</td>
                <td><input type="password" id="oldPassword" class="wu-text easyui-validatebox"
                           data-options="required:true, missingMessage:'请填写密码'"/></td>
            </tr>
            <tr>
                <td width="80" align="right">新密码:</td>
                <td><input type="password" id="newPassword" class="wu-text easyui-validatebox"
                           data-options="required:true, missingMessage:'请填写密码'"/></td>
            </tr>
            <tr>
                <td width="80" align="right">重复新密码:</td>
                <td><input type="password" id="reNewPassword" class="wu-text easyui-validatebox"
                           data-options="required:true, missingMessage:'请填写密码'"/></td>
            </tr>
            <tr>
                <td>&emsp;</td>
                <td>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="submitEdit();">确认修改</a>
                </td>
            </tr>
        </table>
    </form>
</div>

</body>

<!-- End of easyui-dialog -->
<script type="text/javascript">
    function submitEdit() {
        var validate = $("#edit-form").form("validate");
        if (!validate) {
            $.messager.alert("消息提醒", "请检查你输入的数据!", "warning");
            return;
        }
        if ($("#newPassword").val() != $("#reNewPassword").val()) {
            $.messager.alert("消息提醒", "两次密码输入不一致!", "warning");
            return;
        }
        $.ajax({
            url: 'edit_password',
            type: 'post',
            data: {newpassword: $("#newPassword").val(), oldpassword: $("#oldPassword").val()},
            dataType: 'json',
            success: function (data) {
                if (data.type == 'success') {
                    $.messager.alert("消息提醒", "密码修改成功!", "warning");
                } else {
                    $.messager.alert("消息提醒", data.msg, "warning");
                }
            }
        })
    }
</script>